import 'package:flutterdemo/0demo/utils/date_util.dart';

void main() {
  String originUrl = "https://www.baidu.com?wd=aa&status=1";
  originUrl = originUrl.addUrlParamAndOverride("preset", "false");
  originUrl = originUrl.addUrlParamAndOverride("wd", "bb");
  print(originUrl);

  print(currentDate().substring(0, 10));
}

extension on String {
  String addUrlParamAndOverride(String key, String value) {
    String originUrl = this;
    Uri uri = Uri.parse(originUrl);
    Map<String, String> originParam = uri.queryParameters;
    Map<String, String> newParam = Map();
    originParam.forEach((key, value) {
      newParam[key] = value;
    });
    newParam[key] = value;
    Uri newUri = uri.replace(queryParameters: newParam);
    return newUri.toString();
  }
}
